<extend name="Public/base" />
<block name="main">
    <fieldset class="layui-elem-field">
        <legend>产品管理 - {:(isset($detail['id'])?'编辑':'新增')}产品-{$companyInfo['company_name']}</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="">
                <if condition="isset($detail['id'])">
                    <input type="hidden" name="id" value="{$detail['id']}">
                </if>
                <input type="hidden" name="app_code" value="{$detail['app_code']}">
                <input type="hidden" name="company_id" value="{$detail['company_id']}">

                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 产品名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="product_name" required value="{:(isset($detail['product_name'])?$detail['product_name']:'')}" lay-verify="required" placeholder="请输入产品名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 公司名称</label>
                    <div class="layui-form-label">
                        {:(isset($detail['company_name'])?$detail['company_name']:'')}
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 产品ID</label>
                    <div class="layui-form-label">
                        {$detail['app_code']}
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 有效期</label>
                    <div class="layui-input-block">
                        <input type="text" name="valid_date" required value="{:(date('Y-m-d',$detail['valid_date']))}" lay-verify="required" placeholder="请输入产品名称" class="layui-input" style="width:100px;" onclick="layui.laydate({elem: this, istime: true, format: 'YYYY-MM-DD'})">
                    </div>
                </div>
                <if condition="isset($detail['id'])">
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span> 配置</label>
                        <div class="layui-input-block" id="sel"  style="width:100px;" >
                            <select  name="configuration_id"  id="configuration" lay-filter="configuration" lay-verify="">
                                <foreach name="configuration"  item="con" >
                                    <if condition=" $con.id eq $detail.configuration_id ">
                                        <option value="{$con.id}" data-count="{$con.count}" data-name="{$con.name}" data-length="{$con.length}" data-type="{$con.type}"  selected disabled>--{$con.title}--</option>
                                        <else/>
                                        <option value="{$con.id}" data-count="{$con.count}"  data-name="{$con.name}" data-length="{$con.length}" data-type="{$con.type}" disabled>--{$con.title}--</option>
                                    </if>
                                </foreach>
                            </select>
                        </div>
                    </div>
                    <else/>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color:red">*</span> 配置</label>
                        <div class="layui-input-block" id="sel"  style="width:100px;" >
                            <select  name="configuration_id"  id="configuration" lay-filter="configuration">
                                <foreach name="configuration"  item="con" >
                                    <if condition=" $con.id eq $detail.configuration_id ">
                                        <option value="{$con.id}" data-count="{$con.count}"  data-name="{$con.name}" data-length="{$con.length}" data-type="{$con.type}"  selected="selected" disabled="true">--{$con.title}--</option>
                                        <else/>
                                        <option value="{$con.id}" data-count="{$con.count}" data-name="{$con.name}" data-length="{$con.length}" data-type="{$con.type}" >--{$con.title}--</option>
                                    </if>
                                </foreach>
                            </select>
                        </div>
                    </div>
                </if>

                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 签名内容</label>
                    <div id="addTr" class="layui-input-block">
                        <!-- <textarea  name="auth_content" class="layui-textarea">{$detail['auth_content']}</textarea>--> 
                        <if condition="isset($detail['id'])" >
                            {$html}
                            <else />
                            <span id="config"></span>
                        </if>
                    </div>
                    <input type="hidden" id="num" value="{$num}" />
                   
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>

            </form>
        </div>
    </fieldset>
</block>
<block name="myScript">
    <script type="text/javascript" src="__PUBLIC__/layui/lay/modules/laydate.js"></script>
    <if condition="isset($detail['id'])">
        <script>//编辑
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(admin-form)', function(data){
                    $.ajax({
                        type: "POST",
                        url: '{:U("edit")}',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });

            });
        </script>
        <else />
        <script type="text/javascript">
        //添加
            $(function(){
                var arr = $("select option:selected").data("count");//每行个数
                var name =$("select option:selected").data("name");
                var length =$("select option:selected").data("length");
                var type =$("select option:selected").data("type");
                var nameArr = name.split('#');
                var lengthArr = length.split('#');
                var typeArr = type.split('#');
                var j = 1;
                var str = "<span>";
                for (var i = 0; i < arr; i++) {
                    str += '<td>'+nameArr[i]+'：<input type="'+typeArr[i]+'" name="content['+j+']"  style="width:'+lengthArr[i]+'px;" value=""  lay-verify="required"  />&nbsp;</td>';
                    j++;
                }
                str += '<td><input type="button" value="+" id="getAtr" onClick="fun()"></td>';
                str += "<br></span>";
                $("#config").html(str);
                $("#num").val(j);
            });

            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(admin-form)', function(data){
                    $.ajax({
                        type: "POST",
                        url: '{:U("add")}',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });

            });

        </script>
    </if>
    <script type="text/javascript">
        //下拉菜单切换
        layui.use('form', function(){
            var form = layui.form();
            form.on('select(configuration)', function(data){
                $(".addContent").html('');
                var configuration = data.value;
                var arr = $("select option:selected").data("count");//每行个数
                var name =$("select option:selected").data("name");
                var length =$("select option:selected").data("length");
                var type =$("select option:selected").data("type");
                var nameArr = name.split('#');
                var lengthArr = length.split('#');
                var typeArr = type.split('#');
                var str = "<span>";
                var j = 1;
                for (var i = 0; i < arr; i++) {
                    str += '<td>'+nameArr[i]+'：<input type="'+typeArr[i]+'" name="content['+j+']" style="width:'+lengthArr[i]+'px;" value=""  lay-verify="required" />&nbsp;</td>';
                    j++;
                }
                str += '<td><input type="button" value="+" id="getAtr" onClick="fun()"></td>';
                str += "<br></span>";
                $("#config").html(str);
                $("#num").val(j);
            });
        });
        function fun(){
            var arr = $("select option:selected").data("count");//每行个数
            var name =$("select option:selected").data("name");
            var length =$("select option:selected").data("length");
            var type =$("select option:selected").data("type");
            var nameArr = name.split('#');
            var lengthArr = length.split('#');
            var typeArr = type.split('#');
            var $str = "<span  class='addContent'>";
            var j = $("#num").val();
        
            for (var i = 0; i < arr; i++) {
                $str += '<td>'+nameArr[i]+'：<input type="'+typeArr[i]+'" name="content['+j+']" style="width:'+lengthArr[i]+'px;"  value=""  lay-verify="required" />&nbsp;</td>';
                j++;
            }

            $str+="&nbsp;<input type='button' value='-'  onClick='getDel(this)'>";
            $str+="<br>";
            $str+="</span>";
            $("#addTr").append($str);
            $("#num").val(j);
        }
        function getDel(k){
            $(k).parent().remove();
        }
    </script>
</block>